<template>
	<view style="padding: 20rpx;">
		<!-- 用户信息展示，只显示头像和用户名 -->
		<view class="box" style="display: flex; flex-direction: column; align-items: center; justify-content: center; margin-bottom: 40rpx;">
			<image :src="user.avatar" style="width: 180rpx; height: 180rpx; border-radius: 50%;" mode="aspectFill"></image>
			<view style="margin-left: 30rpx;">
				<view style="font-size: 36rpx; font-weight: bold;">{{ user.username }}</view>
			</view>
		</view>

		<!-- 动态导航项，样式宽一些 -->
		<view class="box">
			<navigator :url="getPublishManageUrl()" style="padding: 30rpx; border-bottom: 2rpx solid #eee;">
				<uni-icons type="upload" size="22"></uni-icons>
				<text style="margin-left: 20rpx;">发布管理</text>
				<uni-icons type="right" color="#999" style="float: right;"></uni-icons>
			</navigator>
			<navigator :url="getPersonalInfoUrl()" style="padding: 30rpx; border-bottom: 2rpx solid #eee;">
				<uni-icons type="person" size="22"></uni-icons>
				<text style="margin-left: 20rpx;">个人信息</text>
				<uni-icons type="right" color="#999" style="float: right;"></uni-icons>
			</navigator>
			<navigator url="/pages/password/password" style="padding: 30rpx; border-bottom: 2rpx solid #eee;">
				<uni-icons type="locked" size="22"></uni-icons>
				<text style="margin-left: 20rpx;">修改密码</text>
				<uni-icons type="right" color="#999" style="float: right;"></uni-icons>
			</navigator>
			<navigator url="/pages/aboutUs/aboutUs" style="padding: 30rpx; border-bottom: 2rpx solid #eee;">
				<uni-icons type="help" size="22"></uni-icons>
				<text style="margin-left: 20rpx;">关于我们</text>
				<uni-icons type="right" color="#999" style="float: right;"></uni-icons>
			</navigator>
			<navigator url="/pages/agreement/agreement" style="padding: 30rpx; border-bottom: 2rpx solid #eee;">
				<uni-icons type="info" size="22"></uni-icons>
				<text style="margin-left: 20rpx;">用户协议</text>
				<uni-icons type="right" color="#999" style="float: right;"></uni-icons>
			</navigator>
		</view>

		<!-- 退出登录按钮 -->
		<view style="margin-top: 40rpx; text-align: center;">
			<button @click="logout" style="width: 60%; background-color: #FF4C4C; color: white; padding: 20rpx; border-radius: 50rpx;">
				退出登录
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: uni.getStorageSync('xm-user')
			};
		},
		onShow() {
			this.user = uni.getStorageSync('xm-user');
		},
		methods: {
			// 根据角色返回个人信息页面的URL
			getPersonalInfoUrl() {
				if (this.user.role === 'teacher') {
					return '/pages/person/teacher';  
				} else {
					return '/pages/person/user';    
				} // 默认跳转页面
			},
			// 根据角色返回发布管理页面的URL
			getPublishManageUrl() {
				if (this.user.role === 'teacher') {
					return '/pages/publish/teacher';  // 教师角色的发布管理
				} else{
					return '/pages/publish/user';    // 家长角色的发布管理
				}
			},
			// 退出登录
			logout() {
				uni.removeStorageSync('xm-user');
				uni.redirectTo({
					url: '/pages/login/login'
				});
			}
		}
	};
</script>

<style>
.me-item {
	flex: 1; 
	display: flex; 
	flex-direction: column; 
	align-items: center;
	grid-gap: 10rpx;
}
</style>
